package caip2025n.rcv2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;

public class Main {
	
	//输入优化模板开始
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer st = new StreamTokenizer(br);
	static long rd() throws IOException {
		st.nextToken();
		return (long) st.nval;
	}
	//输入优化模板结束
	
	static long n;
	static long k;
	static ArrayList<Long> a;
	
	//检查容量w的小车能否在k次内运完
	public static boolean check(long w) {
		long sum = 0;
		long count = 0;
		for(int i=0;i<n;i++) {
			if(sum+a.get(i)>w) {
				//需要新开一趟
				count++;
				sum=0;
			}
			sum += a.get(i);
			if(count+1>k) {
				//超过次数限制
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) throws IOException {
		n = rd();
		k = rd();
		
		a = new ArrayList<>();
		//[l,r]表示小车重量单位
		//l初始为最大单个行李重量
		//r初始为全部行李重量和
		long l=0;
		long r=0;
		long ans = 0;

		//读取数据，确定左右届
		for(int i=0;i<n;i++) {
			long tmp = rd();
			l = Math.max(l, tmp);
			r += tmp;
			a.add(tmp);	
		}
		
		//[l,r]区间二分找答案
		while(l<=r) {
			long mid = (l + r)/2;
			//检查mid是否可行
			if(check(mid)) {
				//mid为备选答案
				ans = mid;
				//缩小区间为[l,mid-1]
				r = mid - 1;
			}else {
				//缩小区间为[mid+1,r]
				l = mid + 1;
			}
		}
		
		System.out.print(ans);
	}
}
